var e = require("../../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../../@babel/runtime/regenerator")), a = require("../../../../@babel/runtime/helpers/asyncToGenerator"), n = require("../../../../mycomponent/payKeyboard/PayKeyboardAsync.js"), t = require("../../../../utils/themeSkin/skinBehavior"), r = getApp();

Page({
    behaviors: [ t ],
    data: {
        language: "",
        balance: 0,
        info_form: {
            transfer_id: "",
            transfer_money: ""
        },
        transfer_id: "",
        memberInfo: "",
        balanceLang: "余额",
        payKeyboardShow: !1,
        need_password: !1,
        has_password: !1,
        showConfirm: !1
    },
    onLoad: function(e) {},
    onReady: function() {
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        });
    },
    onShow: function() {
        this.getBalence();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getBalence: function() {
        var e = this, a = r.getNetAddresss("finance.balance.member-balance");
        r._getNetWork({
            url: a,
            success: function(a) {
                var n = a.data;
                1 == n.result && (e.setData({
                    balance: n.data.credit2,
                    need_password: n.data.need_password,
                    has_password: n.data.has_password
                }), wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: e.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                }));
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    payKeyboardComplete: function(e) {
        n.payKeyboardAsync.complete(e.detail);
    },
    getPayKeyboardPassword: function() {
        return this.setData({
            payKeyboardShow: !0
        }), new Promise(function(e, a) {
            n.payKeyboardAsync.addCompleteFn(function(a) {
                e(a);
            });
        });
    },
    payKeyboardClose: function() {
        this.setData({
            payKeyboardShow: !1
        });
    },
    beforeConfirm: function() {
        var n = this;
        return a(e.default.mark(function a() {
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    if (!(parseFloat(n.data.info_form.transfer_money) > parseFloat(n.data.balance))) {
                        e.next = 3;
                        break;
                    }
                    return wx.showToast({
                        icon: "none",
                        title: "转让金额不可大于您的余额",
                        duration: 1500
                    }), e.abrupt("return");

                  case 3:
                    if (!(null == n.data.transfer_id || n.data.transfer_id <= 0 || 0 == n.data.transfer_id.length)) {
                        e.next = 6;
                        break;
                    }
                    return wx.showToast({
                        icon: "none",
                        title: "转让id不可为空",
                        duration: 1500
                    }), e.abrupt("return");

                  case 6:
                    if (!(null == n.data.info_form.transfer_money || n.data.info_form.transfer_money <= 0 || 0 == n.data.info_form.length)) {
                        e.next = 9;
                        break;
                    }
                    return wx.showToast({
                        icon: "none",
                        title: "转让金额不可低于0",
                        duration: 1500
                    }), e.abrupt("return");

                  case 9:
                    if (1 != n.data.need_password || 0 != n.data.has_password) {
                        e.next = 15;
                        break;
                    }
                    return e.next = 12, r.confirm("请先设置支付密码");

                  case 12:
                    return e.sent && wx.navigateTo({
                        url: "/packageA/member/set_balance_password/set_balance_password"
                    }), e.abrupt("return");

                  case 15:
                    n.setData({
                        showConfirm: !0
                    });

                  case 16:
                  case "end":
                    return e.stop();
                }
            }, a);
        }))();
    },
    confirm: function() {
        var n = this;
        return a(e.default.mark(function a() {
            var t, o, s;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    if (t = n, o = r.getNetAddresss("finance.balance.transfer"), o += "&recipient=" + t.data.transfer_id, 
                    o += "&transfer_money=" + t.data.info_form.transfer_money, 1 != n.data.need_password) {
                        e.next = 9;
                        break;
                    }
                    return e.next = 7, n.getPayKeyboardPassword();

                  case 7:
                    s = e.sent, o += "&password=" + s;

                  case 9:
                    r._getNetWork({
                        url: o,
                        success: function(e) {
                            var a = e.data;
                            1 == a.result ? wx.showToast({
                                title: a.msg,
                                icon: "none",
                                duration: 1500,
                                success: function() {
                                    setTimeout(function() {
                                        wx.navigateBack({
                                            delta: 1
                                        });
                                    }, 1500);
                                }
                            }) : wx.showToast({
                                icon: "none",
                                title: a.msg,
                                duration: 1500
                            });
                        },
                        fail: function(e) {
                            console.log(e);
                        }
                    });

                  case 10:
                  case "end":
                    return e.stop();
                }
            }, a);
        }))();
    },
    transferIdinp: function(e) {
        var a = e.detail.value;
        this.setData({
            transfer_id: a
        }), this.getmemberInfo();
    },
    moneyinp: function(e) {
        var a = e.detail.value;
        this.setData({
            "info_form.transfer_money": a
        });
    },
    getmemberInfo: function() {
        var e = this, a = r.getNetAddresss("member.member.memberInfo");
        a += "&uid=" + this.data.transfer_id, r._getNetWork({
            url: a,
            success: function(a) {
                var n = a.data;
                1 == n.result ? e.setData({
                    memberInfo: n.data
                }) : wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    }
});